package com.hotec.PROJECT_NAME.config.security.impl;

import cn.hutool.core.util.ObjectUtil;
import com.google.common.collect.Lists;
import com.hotec.PROJECT_NAME.component.exception.exc.BizException;
import com.hotec.PROJECT_NAME.modules.sys.entity.SysAccount;
import com.hotec.PROJECT_NAME.modules.sys.service.SysAccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Service;

/**
 * @author
 */
@Service
@Slf4j
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    SysAccountService accountService;

    @Override
    public UserDetails loadUserByUsername(String username) {
        SysAccount account = accountService.getOne(new SysAccount().setUsername(username));

        if(ObjectUtil.isNull(account)) throw new BizException("用户名或密码错误");

        return new User(account.getId(), account.getPassword(), Lists.newArrayList());
    }
}
